package com.goldentrail.goldenapp.server;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;

import com.goldentrail.dml.Neo4jBuilder;
import com.goldentrail.dml.Neo4jQuery;
import com.goldentrail.dataobject.DataArtifact;
import com.goldentrail.dataobject.Invocation;
import com.goldentrail.dataobject.Node;
import com.goldentrail.dataobject.Run;
import com.goldentrail.dataobject.User;
import com.goldentrail.dataobject.Workflow;
import com.goldentrail.dataobject.jit;
import com.goldentrail.dot.DOTDriver;
import com.goldentrail.dot.RunToDot;
import com.goldentrail.goldenapp.client.UploadService;
import com.goldentrail.goldenapp.shared.Constants;
import com.goldentrail.parser.ComadTraceParser;
import com.goldentrail.parser.TraceParser;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.goldentrail.db.*;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class UploadServiceImpl extends RemoteServiceServlet implements
   UploadService, Constants {

	  private Hashtable<Node, ArrayList<Node>> nodeIDs = new Hashtable<Node,ArrayList<Node>>();
	  private ArrayList<String> startNodes;
	  private ArrayList<String> throughNodes;
	  private ArrayList<String> endNodes;
	  private String recentResultJSON;
	  private String [][] recentOutputResults;
	  private String [][] recentOtherResults;
	  private String [][] recentInputResults;
	  private String [][] recentQueryResults;
	  // /Users/dey/myData_042011/phd/DToL/FPC/dtol_fpc1_out.trace
	  
	  
	  //This function receives a filename, parses a run, and uploads it into the Neo4j Database.
	  public String upload(String username, String input) { 
		  try {
			TraceParser tp = new TraceParser();
			Run newRun = tp.parse(new File(UPLOAD_DIRECTORY + input));
			ComadTraceParser t = new ComadTraceParser();
			User user = new User();
			user.setUserName(username);
			user.setUserId(username);
			Workflow wf = new Workflow();
			wf.setUserId(username);
			wf.setWfName(input);
			wf.setWfId(input);
			t.insRunDetails(newRun, user, wf);
			
			System.out.println("Finished conversion.");
					
		  } catch (Exception e) {
			  return new String("Error.");
		  }
		  return new String("Finished conversion.");
	  }
	  
	  public String queryLoV(String provType){
		  DBOperation query = new DBOperation(true);
		  Hashtable<String, QueryResult> result = query.getAllLOVs(provType);
		  recentOtherResults = result.get("i").getResult();
		  recentInputResults = result.get("id").getResult();
		  recentOutputResults = result.get("od").getResult();
		  return new String("Finished LoV call.");
	  }
	  
	  public String[][] getRecentOtherResults(){
		  return recentOtherResults;
	  }
	  
	  public String[][] getRecentInputResults(){
		  return recentInputResults;
	  }
	  
	  public String[][] getRecentOutputResults(){
		  return recentOutputResults;
	  }
	  
	  public String[][] queryDB(String provType, String dataCode, ArrayList<String> startNodes, ArrayList<String> endNodes, ArrayList<String> throughNodes){
		  String startNodeList = "NULL";
		  String throughNodeList = "NULL";
		  String endNodeList = "NULL";
		  
		  for(int x = 0; x < startNodes.size(); x++){
			  if (x == 0){
				  startNodeList = startNodes.get(0);
			  }
			  else {
				  startNodeList = startNodeList + ", " + startNodes.get(x);
			  }
		  }
		  
		  for(int x = 0; x < throughNodes.size(); x++){
			  if (x == 0){
				  throughNodeList = throughNodes.get(0);
			  }
			  else {
				  throughNodeList = throughNodeList + ", " + throughNodes.get(x);
			  }
		  }
		  
		  for(int x = 0; x < endNodes.size(); x++){
			  if (x == 0){
				  endNodeList = endNodes.get(0);
			  }
			  else {
				  endNodeList = endNodeList + ", " + endNodes.get(x);
			  }
		  }
		  
		  DBOperation query = new DBOperation(true);
		  QueryResult results = query.getDEP(provType, dataCode, startNodeList, endNodeList, throughNodeList);
		  recentQueryResults = results.getResult();
		  buildJSON(dataCode);
		  
		  RunToDot dotConver = new RunToDot();
		  dotConver.conversion(recentQueryResults);
		  DOTDriver dotToImage = new DOTDriver();
		  dotToImage.write(dotToImage.getGraph(new File(GRAPH_DIRECTORY)), GRAPH_OUTPUT_DIRECTORY);
		  
		  return recentQueryResults;
	  }
	  
	  public String getRecentResults(){
		  return recentResultJSON;
	  }
	  
	  //This function retrieves the run IDs from the Neo4j DB, and returns it through an encoded string.
	  public String getRunIDs(){
		  ArrayList<String> runIDs = Neo4jQuery.getRunIds();
		  String runIDList = "";
		  for (int x = 0; x < runIDs.size(); x++){
			  runIDList = runIDList + runIDs.get(x) + "\n";
		  }
		  if (runIDList.equals("")){
			  runIDList = "empty";
		  }
		  return runIDList;
	  }
	  
	  //This function retrieves all invocation IDs of a specific runID from the Neo4j DB, and returns it through an encoded string.
	  public String getInvocationIDs(String runID){
		  System.out.println("Getting Invocation IDs.");
		  ArrayList<String> invocationIDs = Neo4jQuery.getInvocIds(runID);
		  System.out.println("InvocationIDs.size() :" + invocationIDs.size());
		  String runIDList = "";
		  for (int x = 0; x < invocationIDs.size(); x++){
			  runIDList = runIDList + invocationIDs.get(x) + "\n";
		  }
		  return runIDList;
	  }
	  
	  public String getDataArtifacts(String RunID){
		  System.out.println("Getting Data Artifacts.");
		  ArrayList<String> artifactIDs = Neo4jQuery.getDataArtifactIds(RunID);
		  String runIDList = "";
		  for (int x = 0; x < artifactIDs.size(); x++){
			  runIDList = runIDList + artifactIDs.get(x) + "\n";
		  }
		  return runIDList;
	  }
	  
	  //This function is called if only a runID is provided in the GUI.
	  public ArrayList<String> retrieveGraph(String runID){
		  Run retrievedRun = Neo4jQuery.getRun(runID);
		  ArrayList<String> invocationResults = fillInvocationResults(retrievedRun);
		  System.out.println(recentResultJSON);
		  return invocationResults;
	  }
	  
	  //This function is called if arguments are inputted in the flextable.
	  public ArrayList<String> retrieveCompleteGraph(ArrayList<String> inStartNodes, ArrayList<String> inThroughNodes, ArrayList<String> inEndNodes, String runID){
		  startNodes = inStartNodes;
		  throughNodes = inThroughNodes;
		  endNodes = inEndNodes;
		  ArrayList<Invocation> invocationList;
		  if (throughNodes.size() > 0){
			  //This partition branches depending on the flextable data, under the assumption that we have 'through' nodes to use.
			  ArrayList<Node> throughNodeList = initializeNodeList(throughNodes);
			  if (startNodes.size() == 0 && endNodes.size() == 0){
				  invocationList = Neo4jQuery.getPaths(null, throughNodeList, runID);
			  }
			  else if (startNodes.size() == 0){
				  ArrayList<Node> endList = initializeNodeList(endNodes);
				  System.out.println("End List: " + endList);
				  System.out.println("ThroughNodeList: " + throughNodeList);
				  System.out.println("RunID: " + runID);
				  invocationList = Neo4jQuery.getDependents(endList, throughNodeList, runID);
			  }
			  else if (endNodes.size() == 0){
				  ArrayList<Node> startList = initializeNodeList(startNodes);
				  System.out.println("Start List: " + startList);
				  System.out.println("ThroughNodeList: " + throughNodeList);
				  System.out.println("RunID: " + runID);
				  invocationList = Neo4jQuery.getDependencies(startList, throughNodeList, runID);
			  }
			  else {
				  initializeHashTable();
				  invocationList = Neo4jQuery.getPaths(nodeIDs, throughNodeList, runID);
			  }
		  }
		  else {
			  //This partition assumes there are no through nodes provided in the flextable.
			  if (startNodes.size() == 0 && endNodes.size() == 0){
				  invocationList = Neo4jQuery.getPaths(null, null, runID);
			  }
			  else if (startNodes.size() == 0){
				  ArrayList<Node> endList = initializeNodeList(endNodes);
				  System.out.println("End List: " + endList);
				  System.out.println("RunID: " + runID);
				  invocationList = Neo4jQuery.getDependents(endList, null, runID);
			  }
			  else if (endNodes.size() == 0){
				  ArrayList<Node> startList = initializeNodeList(startNodes);
				  System.out.println("Start List: " + startList);
				  System.out.println("RunID: " + runID);
				  invocationList = Neo4jQuery.getDependencies(startList, null, runID);
			  }
			  else {
				  initializeHashTable();
				  invocationList = Neo4jQuery.getPaths(nodeIDs, null, runID);
			  }
		  }
		  System.out.println("Size of the Invocation List: " + invocationList.size());
		  ArrayList<String> results = fillInvocationResults(invocationList);
//		  RunToDot dotConver = new RunToDot();
//		  dotConver.conversion(retrievedRun);
//		  DOTDriver dotToImage = new DOTDriver();
		  //dotToImage.getGraph(new File("webapps/GoldenApp/dot/graph.txt"));
//		  dotToImage.write(dotToImage.getGraph(new File(GRAPH_DIRECTORY)), GRAPH_OUTPUT_DIRECTORY);
		  return results;
	  }
	  
	  //This function is deprecated, and is only retained for reverting purposes.
	  public String convertGraph(){
		  	DOTDriver driver = new DOTDriver();
		  	byte[] image = null;
		  	image = driver.getGraph(new File(GRAPH_DIRECTORY));
			System.out.println("Finished making the graph.");

	    	File to = new File("webapps/GoldenApp/dot/graph.gif");
		    try {
			   FileOutputStream fos = new FileOutputStream(to);
			   fos.write(image);
			   fos.close();
			} catch (Exception e) { 
				System.out.println(e.getMessage());
			}
		  return new String("Finished making the graph.");
	  }
	  
	  //The next three functions initialize the hash table to be forwarded to Neo4j.
	  private void initializeHashTable(){
		    nodeIDs.clear();
			initializeHashTableWOThrough();
		}
		
		private void initializeHashTableWOThrough(){
			for (int x = 0; x < startNodes.size(); x++){
				Node start = new Node();
				start.setNodeId(startNodes.get(x).split(" ")[2]);
				start.setNodeTp("data");
				ArrayList<Node> endlist = new ArrayList<Node>();
				for (int y = 0; y < endNodes.size(); y++){
					Node end = new Node();
					end.setNodeId(endNodes.get(y).split(" ")[2]);
					end.setNodeTp("data");
					endlist.add(end);
				}
				nodeIDs.put(start, endlist);
			}
		}
		
		private void initializeHashTableAll(){
			for (int x = 0; x < startNodes.size(); x++){
				Node start = new Node();
				start.setNodeId(startNodes.get(x).split(" ")[2]);
				start.setNodeTp("data");
				ArrayList<Node> endlist = new ArrayList<Node>();
				for (int y = 0; y < throughNodes.size(); y++){
					Node end = new Node();
					end.setNodeId(throughNodes.get(y).split(" ")[2]);
					end.setNodeTp("invoc");
					endlist.add(end);
				}
				nodeIDs.put(start, endlist);
			}
			for (int x = 0; x < throughNodes.size(); x++){
				Node start = new Node();
				start.setNodeId(throughNodes.get(x).split(" ")[2]);
				start.setNodeTp("invoc");
				ArrayList<Node> endlist = new ArrayList<Node>();
				for (int y = 0; y < endNodes.size(); y++){
					Node end = new Node();
					end.setNodeId(endNodes.get(y).split(" ")[2]);
					end.setNodeTp("data");
					endlist.add(end);
				}
				nodeIDs.put(start, endlist);
			}
		}
		
		//This creates a list of nodes with a set of IDs passed in.
		private ArrayList<Node> initializeNodeList (ArrayList<String> NodeIDs){
			
			ArrayList<Node> returnList = new ArrayList<Node>();
			for (int x = 0; x < NodeIDs.size(); x++){
				  Node throughNode = new Node();
				  System.out.println("NodeID before Split: " + NodeIDs.get(x));
				  throughNode.setNodeId((NodeIDs.get(x).split(" ")[2]));
				  if (NodeIDs.get(x).split(" ")[0].equals("Data")){
					  throughNode.setNodeTp("data");
				  }
				  else {
					  throughNode.setNodeTp("invoc");
				  }
				  System.out.println("New Node: " + throughNode.getNodeId() + "," + throughNode.getNodeTp());
				  returnList.add(throughNode);
			}
			return returnList;
		}
		
		private ArrayList<String> fillInvocationResults(Run returnedRun){
			//Populate the recentResults JSONArray for retrieval later.
			recentResultJSON = jit.getJITJSONfromInvocs(returnedRun.getInvocations()).toString();
			
			//Build the arraylist to return via the asynchronous return.
			ArrayList<String> result = new ArrayList<String>();
			ArrayList<Invocation> data = returnedRun.getInvocations();
			for (int x = 0; x < data.size(); x++){
				String arrayInput = "";
				Invocation current = data.get(x);
				String invocationID = current.getInvocationId();
				Hashtable<String, DataArtifact> htIn = current.getInputData();
				Hashtable<String, DataArtifact> htOut = current.getOutputData();
				for (Enumeration<String> e = htIn.keys(); e.hasMoreElements();) {
					String inputData = e.nextElement();
					arrayInput = invocationID + "\n" + inputData + "\n" + "input";
					result.add(arrayInput);
				}
				for (Enumeration<String> f = htOut.keys(); f.hasMoreElements();) {
					String outputData = f.nextElement();
					arrayInput = invocationID + "\n" + outputData + "\n" + "output";
					result.add(arrayInput);
				}
			}
			return result;
		}
		
		private ArrayList<String> fillInvocationResults(ArrayList<Invocation> returnedInvocations){
			//Populate the recentResults JSONArray for retrieval later.
			recentResultJSON = jit.getJITJSONfromInvocs(returnedInvocations).toString();
			
			//Build the arraylist to return via the asynchronous return.
			ArrayList<String> result = new ArrayList<String>();
			ArrayList<Invocation> data = returnedInvocations;
			for (int x = 0; x < data.size(); x++){
				String arrayInput = "";
				Invocation current = data.get(x);
				String invocationID = current.getInvocationId();
				Hashtable<String, DataArtifact> htIn = current.getInputData();
				Hashtable<String, DataArtifact> htOut = current.getOutputData();
				for (Enumeration<String> e = htIn.keys(); e.hasMoreElements();) {
					String inputData = e.nextElement();
					arrayInput = invocationID + "\n" + inputData + "\n" + "input";
					result.add(arrayInput);
				}
				for (Enumeration<String> f = htOut.keys(); f.hasMoreElements();) {
					String outputData = f.nextElement();
					arrayInput = invocationID + "\n" + outputData + "\n" + "output";
					result.add(arrayInput);
				}
			}
			return result;
		}
		
		private void buildJSON(String dep){
			if (recentQueryResults.length == 0){
				return;
			}
			buildInputNodeClones(dep);
			
			if (dep.equals("ddep")){
				buildDataJSON();
			}
			else if (dep.equals("idep")){
				buildInvocationJSON();
			}
			else {
				buildDepJSON();
			}
		}  
		
		
		private void buildDataJSON(){
			String nodeName = recentQueryResults[0][0];
			recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
			recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#FAFAD2\", \"$dim\": 10}, ";
			recentResultJSON = recentResultJSON + "\"adjacencies\": [";
			for (int x = 0; x < recentQueryResults.length; x++){
				if (recentQueryResults[x][0].equals(nodeName)){ //If we haven't changed node references yet, keep adding adjacencies
					recentResultJSON = recentResultJSON + "{\"nodeTo\": \"" + recentQueryResults[x][1] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
				else { //We've found a new node name, close the current block, and start a new one.
					nodeName = recentQueryResults[x][0];
					recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2); //Chop off the last comma
					recentResultJSON = recentResultJSON + "]},{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
					recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#FAFAD2\", \"$dim\": 10}, ";
					recentResultJSON = recentResultJSON + "\"adjacencies\": [{\"nodeTo\": \"" + recentQueryResults[x][1] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
			}
			recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2) + "]}]";
		}
		
		private void buildInvocationJSON(){
			String nodeName = recentQueryResults[0][1];
			recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
			recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#006400\"}, ";
			recentResultJSON = recentResultJSON + "\"adjacencies\": [";
			for (int x = 0; x < recentQueryResults.length; x++){
				if (recentQueryResults[x][1].equals(nodeName)){ //If we haven't changed node references yet, keep adding adjacencies
					recentResultJSON = recentResultJSON + "{\"nodeTo\": \"" + recentQueryResults[x][0] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
				else { //We've found a new node name, close the current block, and start a new one.
					nodeName = recentQueryResults[x][1];
					recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2); //Chop off the last comma
					recentResultJSON = recentResultJSON + "]},{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
					recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#006400\"}, ";
					recentResultJSON = recentResultJSON + "\"adjacencies\": [{\"nodeTo\": \"" + recentQueryResults[x][0] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
			}
			recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2) + "]}]";
		}
		
		private void buildDepJSON(){
			String nodeName = recentQueryResults[0][0];
			recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
			if (recentQueryResults[0][2].equals("u")){ //Used
				recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
			}
			else if (recentQueryResults[0][2].equals("g")){ //Genby
				recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#FAFAD2\", \"$dim\": 10}, ";
			}
			//Add the adjacency block
			recentResultJSON = recentResultJSON + "\"adjacencies\": [";
			for (int x = 0; x < recentQueryResults.length; x++){
				if (recentQueryResults[x][0].equals(nodeName)){ //If we haven't changed node references yet, keep adding adjacencies
					recentResultJSON = recentResultJSON + "{\"nodeTo\": \"" + recentQueryResults[x][1] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
				else { //We've found a new node name, close the current block, and start a new one.
					nodeName = recentQueryResults[x][0];
					recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2); //Chop off the last comma
					recentResultJSON = recentResultJSON + "]},{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
					if (recentQueryResults[x][2].equals("u")){ //Used
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
					}
					else if (recentQueryResults[x][2].equals("g")){ //Genby
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#FAFAD2\", \"$dim\": 10}, ";
					}
					//Add the adjacency block
					recentResultJSON = recentResultJSON + "\"adjacencies\": [{\"nodeTo\": \"" + recentQueryResults[x][1] + "\", \"nodeFrom\": \"" + nodeName + "\"}, ";
				}
			}
			recentResultJSON = recentResultJSON.substring(0, recentResultJSON.length()-2) + "]}]";
			
		}
		
		private void buildInputNodeClones(String dep){
			Hashtable <String, ArrayList<String>> inputNodeList = new Hashtable<String, ArrayList<String>>(); //Key = unique node name, Value = list of it's inputs
			Hashtable <String, Integer> outputNodeLength = new Hashtable<String, Integer>();
			for (int x = 0; x < recentQueryResults.length; x++){
				String nodeName = recentQueryResults[x][0];
				String secondNode = recentQueryResults[x][1];
				if (inputNodeList.containsKey(secondNode)){
					inputNodeList.get(secondNode).add(nodeName);
				}
				else {
					ArrayList<String> newInput = new ArrayList<String>();
					newInput.add(recentQueryResults[x][2]);
					newInput.add(nodeName);
					inputNodeList.put(secondNode, newInput);
				}
				if (!inputNodeList.containsKey(nodeName)){
					ArrayList<String> newInput = new ArrayList<String>();
					newInput.add(recentQueryResults[x][2]);
					inputNodeList.put(nodeName, newInput);
				}
				
				if (outputNodeLength.containsKey(nodeName)){ //If it's already in the list, it's been seen as an output once.
					outputNodeLength.put(nodeName, 1);
				}
				else if (!outputNodeLength.containsKey(secondNode)){
					outputNodeLength.put(secondNode, 0);
				}
			}
			recentResultJSON = "[";
			for (Enumeration<String> e = inputNodeList.keys(); e.hasMoreElements();){
				String nodeName = e.nextElement();
				ArrayList<String> inputList = inputNodeList.get(nodeName);
				if (inputList.size() == 1){
					if (inputList.get(0).equals("u")){
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
					else if (inputList.get(0).equals("g")){
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#FAFAD2\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
					else if (inputList.get(0).equals("i")){
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#FAFAD2\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
					else {
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
				}
			}
			
			for (Enumeration<String> e = outputNodeLength.keys(); e.hasMoreElements();){
				String nodeName = e.nextElement();
				if (outputNodeLength.get(nodeName) == 0){
					if (dep.equals("idep")){
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"rectangle\" , \"$color\": \"#FAFAD2\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
					else if (dep.equals("ddep")){
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
					else {
						recentResultJSON = recentResultJSON  + "{\"name\": \"" + nodeName + "\", \"id\": \"" + nodeName + "\", ";
						recentResultJSON = recentResultJSON + "\"data\": {\"$type\": \"circle\" , \"$color\": \"#006400\"}, ";
						recentResultJSON = recentResultJSON + "\"adjacencies\": []},";
					}
				}
			}
		}
}
